﻿<Page x:Class="Vision.VisionWorkshop.Workshop"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:apt="clr-namespace:System.Activities.Presentation.Toolbox;assembly=System.Activities.Presentation"        
      xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"      
      xmlns:my="clr-namespace:Vision.VisionWorkshop.Controls"    
      xmlns:common="clr-namespace:Vision.VisionWorkshop.Common"
      xmlns:sapm="clr-namespace:System.Activities.Presentation.Model;assembly=System.Activities.Presentation"
      Title="Vision Workshop" Margin="0" ShowsNavigationUI="False">    
    <Grid>
        <Grid.Resources>
            <common:GreaterThanVisibilityConverter x:Key="GreaterThanVisibilityConverter" />
            <common:NullBoolConverter x:Key="NullBoolConverter" />
            <common:OpacityBoolConverter x:Key="OpacityBoolConverter" />
            <common:InverseBoolConverter x:Key="InverseBoolConverter" />
            <common:ModelPropertyValueConverter x:Key="ModelPropertyValueConverter"/>
            <common:ToModelItemCollectionConverter x:Key="ToModelItemCollectionConverter" />
            <HierarchicalDataTemplate DataType="{x:Type sapm:ModelItem}" ItemsSource="{Binding Path=Properties}">
            <StackPanel>
                    <StackPanel.ToolTip>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock FontStyle="Italic" Text="Type:"/>
                            <TextBlock FontWeight="Bold" Text="{Binding Path=ItemType}"/>
                        </StackPanel>
                    </StackPanel.ToolTip>
                    <TextBlock Text="{Binding}"/>
                </StackPanel>
            </HierarchicalDataTemplate>            
            <HierarchicalDataTemplate DataType="{x:Type sapm:ModelProperty}" ItemsSource="{Binding Path=Value, Converter={StaticResource ModelPropertyValueConverter}}">
                <StackPanel>
                    <StackPanel.ToolTip>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock FontStyle="Italic" Text="Property Type: "/>
                            <TextBlock FontWeight="Bold" Text="{Binding Path=PropertyType}"/>
                        </StackPanel>
                    </StackPanel.ToolTip>
                    <TextBlock Text="{Binding Path=Name}"/>
                </StackPanel>
            </HierarchicalDataTemplate>            
            <Style TargetType="{x:Type apt:ToolboxControl}">
                <Style.Resources>
                    <common:ToolboxItemWrapperIconConverter x:Key="iconConverter" DefaultResource="GenericLeafActivityIcon"/>
                </Style.Resources>
                <Setter Property="ToolTemplate">
                    <Setter.Value>
                        <DataTemplate DataType="{x:Type apt:ToolboxItemWrapper}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*" SharedSizeGroup="toolLabel"/>
                                </Grid.ColumnDefinitions>

                                <Rectangle Width="14" Height="14" Margin="2">
                                    <Rectangle.Fill>
                                        <DrawingBrush Drawing="{Binding Converter={StaticResource iconConverter}}"/>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock Text="{Binding DisplayName}" Grid.Column="1" VerticalAlignment="Center"/>
                            </Grid>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="24"/>
            <RowDefinition Height="28"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Menu Grid.Row="0" MenuItem.Click="Menu_Click" Background="#BCC7D8">
            <MenuItem Header="_File">
                <MenuItem Header="_New"/>
                <MenuItem Header="_Open"/>
                <MenuItem Header="_Save"/>
                <Separator/>
                <MenuItem Header="_Run"/>                
            </MenuItem>
            <MenuItem Header="_View">
                <MenuItem Header="Toolbox" IsChecked="{Binding ElementName=Pane1, Path=IsHidden, Mode=TwoWay, Converter={StaticResource InverseBoolConverter}}" IsCheckable="True" />
                <MenuItem Header="Workflow Outline" IsChecked="{Binding ElementName=Pane4, Path=IsHidden, Converter={StaticResource InverseBoolConverter}}" IsCheckable="True" />
                <MenuItem Header="Properties" IsChecked="{Binding ElementName=Pane2, Path=IsHidden, Converter={StaticResource InverseBoolConverter}}" IsCheckable="True" />
                <MenuItem Header="Output Window" IsChecked="{Binding ElementName=Pane3, Path=IsHidden, Converter={StaticResource InverseBoolConverter}}" IsCheckable="True" />
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Header="_View Help"/>
                <Separator/>
                <MenuItem Header="_About"/>
            </MenuItem>
        </Menu>        
        <ToolBar Grid.Row="1" Background="#BCC7D8">
            <Button CommandParameter="New" Click="toolbarButton_Click" ToolTip="New"><Image Source="Images/new.png" /></Button>
            <Button CommandParameter="Open" Click="toolbarButton_Click" ToolTip="Open"><Image Source="Images/open.png" /></Button>
            <Button CommandParameter="Save" Click="toolbarButton_Click" ToolTip="Save"
                    IsEnabled="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource NullBoolConverter}, ConverterParameter='!null'}"
                    Opacity="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource OpacityBoolConverter}, ConverterParameter='null,.4'}">
                <Image Source="Images/save.png" />
            </Button>
            <Button CommandParameter="Run"  Click="toolbarButton_Click" ToolTip="Run"
                    IsEnabled="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource NullBoolConverter}, ConverterParameter='!null'}"
                    Opacity="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource OpacityBoolConverter}, ConverterParameter='null,.4'}">
                <Image Source="Images/run.png" />
            </Button>
            <Button CommandParameter="FileManager"  Click="toolbarButton_Click" ToolTip="File Manager"
                    IsEnabled="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource NullBoolConverter}, ConverterParameter='!null'}"
                    Opacity="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource OpacityBoolConverter}, ConverterParameter='null,.4'}">
                <Image Source="Images/filemanager.png" />
            </Button>
            <Button CommandParameter="Scheduling"  Click="toolbarButton_Click" ToolTip="Scheduling"
                    IsEnabled="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource NullBoolConverter}, ConverterParameter='!null'}"
                    Opacity="{Binding ElementName=dockManager, Path=ActiveDocument, Converter={StaticResource OpacityBoolConverter}, ConverterParameter='null,.4'}">
                <Image Source="Images/scheduling.png" />
            </Button>            
        </ToolBar>
        <ad:DockingManager x:Name="dockManager" Grid.Row="2" Margin="0" Loaded="dockManager_Loaded">
            <ad:ResizingPanel Orientation="Vertical">
                <ad:ResizingPanel Orientation="Horizontal">
                    <ad:DockablePane ad:ResizingPanel.ResizeWidth="175">
                        <ad:DockableContent  Title="Toolbox" Name="Toolbox">
                            <apt:ToolboxControl Name="ctlToolbox" Margin="0" Loaded="ctlToolbox_Loaded"/>    
                        </ad:DockableContent>
                        <ad:DockableContent  Title="Properties" Name="Properties">
                            <ContentPresenter x:Name="ctlPropertiesWindow"/>    
                        </ad:DockableContent>
                        <ad:DockableContent  Title="Document Outline" Name="DocumentOutline">                            
                        </ad:DockableContent>
                    </ad:DockablePane>
                    <ad:DocumentPane />                                            
                </ad:ResizingPanel>
                <ad:DockablePane ad:ResizingPanel.ResizeHeight="140">
                    <ad:DockableContent Title="Output Window" Name="OutputWindow">
                        <Grid Margin="0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="22"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="8" Foreground="Blue" Content="Clear" x:Name="btnClearOutput" MouseLeftButtonDown="btnClearOutput_MouseLeftButtonDown"/>
                            <TextBox Grid.Row="1" Margin="0" x:Name="txtOutput" VerticalScrollBarVisibility="Visible"/>
                        </Grid>
                    </ad:DockableContent>
                </ad:DockablePane>
            </ad:ResizingPanel>
        </ad:DockingManager>        
    </Grid>
</Page>
